<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

	class ParkController extends AdminBaseController
	{
	    
		/*园区列表页*/	
		public function index(){
		$where['status'] = 1;
		/**搜索条件**/
		$incubator_type = $this->request->param('incubator_type');
		//$address = $this->request->param('address');

		if ($incubator_type) {
			$where['incubator_type'] = $incubator_type;
		}

		
		if(session('incubator_id')){
			$where['incubator_id']=session('incubator_id');
		}
		$list=Db::name('incubator')->where($where)->order("sort ASC")->paginate(10);
		if(!$incubator_type){
			$incubator_type=0;
		}
		$page=$list->render();
		$this->assign("page", $page);
		$this->assign('incu_type',$incubator_type);
		// echo $incubator_type;
		// exit;
		$this->assign("list", $list);
		return $this->fetch();
	}



	/*园区添加*/		
	public function addPark(){
		
		if($_POST){
			$data['incubator_type'] = $this->request->param('incubator_type',0,'intval');
			$data['park_type'] = $this->request->param('park_type',0,'intval');
			$data['incubator_name'] = $this->request->param('incubator_name','');
			$data['station_total_num']=	$this->request->param('station_total_num',0);
			$data['pic_url'] = $this->request->param('pic_url','');
			$data['address'] = $this->request->param('address','');
			$data['tel'] = $this->request->param('tel','');
			$data['describe'] = $this->request->param('describe','');
			$data['sort'] = $this->request->param('sort',0);
			$data['is_use'] = $this->request->param('is_use',1);
			// echo $incubator_name ;
			// if($type_id==1){
			// 	$station_	
			// }					

			// echo $type_id;
			
			$add=Db::name('incubator')->insert($data);
			if($add){
				$this->success('添加成功','Park/index');
			}else{
				$this->error('添加失败');
			}	
		}else{
			return $this->fetch();
		}
		





	}
	/*详情*/
	public function detailPark(){
			$where=array();
			$id= $this->request->param('id',0,'intval');
			if($id){
				$where['id']= $id;
			}else{
				$this->error('该信息id不能为空');
			}
			$detail= Db::name('incubator')->where($where)->find();
			
			$this->assign('detail',$detail);
			return $this->fetch();
		}

		/*编辑园区*/	
		public function editPark(){
			if($_POST){
				$edit = Db::name('incubator')->update($_POST);
				// if($edit){
					$this->success('编辑成功','index');
				// }
			}
			$where=array();
			$id= $this->request->param('id',0,'intval');
			if($id){
				$where['id']= $id;
			}else{
				$this->error('该信息id不能为空');
			}
			$detail= Db::name('incubator')->where($where)->find();
		
			$this->assign('detail',$detail);
			return $this->fetch();

		}


		/*删除园区*/
		public function delPark(){
			$data['id']= $this->request->param('id',0,'intval');
			$type= $this->request->param('cancel',0,'intval');
			if($type){
				$is_use=db('incubator')->where('id',$data['id'])->value('is_use');
				if($is_use==1){
					return '已被取消禁用';
				}
				$data['is_use']=1;

				$del=Db::name('incubator')->update($data);
				if($del){
					return '取消禁用成功';
				}else{
					return '取消禁用失败';
				}
			}else{


				$is_use=db('incubator')->where('id',$data['id'])->value('is_use');
				if($is_use==2){
					return '已被禁用';
				}
				$data['is_use']=2;

				$del=Db::name('incubator')->update($data);
				if($del){
					return '禁用成功';
				}else{
					return '禁用失败';
				}
			}

		}
		function delete(){
				$data['id']= $this->request->param('id',0,'intval');
				$sta=db('incubator')->where('id',$data['id'])->delete();
				if($sta){
					return 1;
				}else{
					return 0;
				}

		}	








































}